package com.fenghongzhang.day005test2.view;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.fenghongzhang.day005test2.R;
import com.fenghongzhang.day005test2.contract.UserContract;
import com.fenghongzhang.day005test2.entity.User;
import com.fenghongzhang.day005test2.model.UserModel;
import com.fenghongzhang.day005test2.presenter.UserPresenter;
import com.fenghongzhang.mvp_lib.view.BaseFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class RegisterFragment extends BaseFragment<UserPresenter> implements UserContract.IUserView {

    @BindView(R.id.fg_name)
    EditText fgName;
    @BindView(R.id.fg_pwd)
    EditText fgPwd;
    @BindView(R.id.fg_register)
    Button fgRegister;
    @BindView(R.id.fg_login)
    Button fgLogin;

    private static final String TAG = "RegisterFragment";


    public interface MyListener{
        void click(int i);
    }

    private MyListener myListener;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myListener = (MyListener) getActivity();
        
    }

    @Override
    public String getName() {
        return fgName.getText().toString();
    }

    @Override
    public String getPwd() {
        return fgPwd.getText().toString();
    }

    @Override
    public void ShowMsg(User user) {
        Toast.makeText(getActivity(), user.getMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public int bindLayout() {
        return R.layout.fragment_register;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this, mFView);
    }

    @Override
    public void initDate() {
        //dagger2
        presenter = new UserPresenter(new UserModel(), this);

    }

    @Override
    public void showToast(String s) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @OnClick(R.id.fg_register)
    public void onViewClicked() {
        presenter.registerUser();
    }

    @OnClick(R.id.fg_login)
    public void onViewClicked1() {
        myListener.click(1);
    }


}
